<!-- 确定评估-查看表格 -->
<template>
  <el-table :data="dataList" :span-method="objectSpanMethod" :header-cell-style="handerMethod" class="normal-table"
    v-loading="loading" v-if="isShow">
    <el-table-column label="评估区域" prop="area" align="center">
      <el-table-column label="" prop="provinceName" align="center">
        <template #default="{ row }">
          {{ areaName(row.provinceName, row.cityName, row.countyName) }}
        </template>
      </el-table-column>
      <el-table-column label="" prop="cityName" align="center" />
      <el-table-column label="" prop="countyName" align="center" />
    </el-table-column>
    <!-- 地理id(虚拟ID) 或 房屋单体数据ID -->
    <el-table-column prop="geographyId" align="center" min-width="110px">
      <template #header>
        <div>地理ID</div>
        <div>（虚拟的ID）</div>
      </template>
    </el-table-column>
    <!-- <el-table-column label="烈度" prop="condition" align="center" v-if="form.seismicInputMode1 == '0'"> -->
    <el-table-column label="烈度" prop="intensity" align="center" v-if="form.seismicInputMode1 == '0'">
      <template #default="{ row }">
        <span v-if="URL.casualtiesDE == props.url">{{ row.intensity }}</span>
        <DictTag :code="CODE.ld" :value="row.condition" v-else></DictTag>
      </template>
    </el-table-column>
    <el-table-column label="超越概率" prop="condition" align="center" v-if="form.seismicInputMode1 == '1'">
      <template #default="{ row }">
        <DictTag :code="CODE.sgglsz" :value="row.condition"></DictTag>
      </template>
    </el-table-column>
    <!-- 确定评估-人员伤亡 -->
    <template v-if="URL.casualtiesDE == props.url">
      <el-table-column prop="casualties" align="center" min-width="125px">
        <template #header>
          <div>人员伤亡</div>
          <div>（重伤、伤亡）</div>
        </template>
        <template #default="{ row }">
          <DictTag :code="CODE.rysw" :value="row.casualties"></DictTag>
        </template>
      </el-table-column>
      <el-table-column label="时间段" prop="time" align="center" min-width="125px">
        <template #header>
          <div>时间段</div>
          <div>（白天、夜间）</div>
        </template>
        <template #default="{ row }">
          <DictTag :code="CODE.sjd" :value="row.time"></DictTag>
        </template>
      </el-table-column>
    </template>
    <!-- 确定评估-结构破坏 -->
    <template v-if="URL.resistEarthquakesDE == props.url">
      <el-table-column label="破坏程度" prop="" align="center">
        <template #default="{ row }">
          <DictTag :code="CODE.phcd" :value="row.damageDegree"></DictTag>
        </template>
      </el-table-column>
    </template>
    <el-table-column prop="calculatedValue" align="center" min-width="100px">
      <template #header>
        <div>计算值</div>
        <span v-if="URL.casualtiesDE == props.url">（人）</span>
        <span v-if="URL.EconomicLossED == props.url">（万元）</span>
      </template>
      <template #default="{ row }">
        <div v-if="URL.resistEarthquakesDE == props.url">
          <span v-if="row.calculatedValue!=9999.9999">{{ row.calculatedValue }}</span>
          <span v-else></span>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="correctionValue" align="center" min-width="100px">
      <template #header>
        <div>经验评估与修正值</div>
        <span v-if="URL.casualtiesDE == props.url">（人）</span>
        <span v-if="URL.EconomicLossED == props.url">（万元）</span>
      </template>
      <template #default="{ row }">
        <el-input v-model="row.correctionValue" v-inputNumber="6" v-if="URL.resistEarthquakesDE == props.url&&(row.correctionValue!=9999.9999)" ></el-input>
        <el-input v-inputNumber="6" v-else-if="URL.resistEarthquakesDE == props.url&&(row.correctionValue==9999.9999)" :disabled="row.correctionValue==9999.9999"></el-input>
        <el-input v-model="row.correctionValue" v-inputNumber="6" v-else></el-input>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center" width="80px">
      <template #default="{ row }">
        <el-link type="primary" :underline="false" @click="updateRow(row)" :disabled="row.calculatedValue==9999.9999">修改</el-link>
      </template>
    </el-table-column>
  </el-table>
  <el-table :data="dataList" border class="normal-table" row-key="id" :default-expand-all="false"
    v-loading="loading" v-else>
    <el-table-column label="评估区域" prop="districtName" align="center"/>
    <!-- <el-table-column label="烈度" prop="condition" align="center" v-if="form.seismicInputMode1 == '0'"> -->
    <el-table-column label="烈度" prop="condition" align="center" v-if="form.seismicInputMode1 == '0'">
      <!-- <template #default="{ row }">
        <span v-if="URL.casualtiesDE == props.url">{{ row.intensity }}</span>
        <DictTag :code="CODE.ld" :value="row.condition" v-else></DictTag>
      </template> -->
    </el-table-column>
    <el-table-column label="超越概率" prop="condition" align="center" v-if="form.seismicInputMode1 == '1'">
      <template #default="{ row }">
        <DictTag :code="CODE.sgglsz" :value="row.condition"></DictTag>
      </template>
    </el-table-column>
    <!-- 确定评估-人员伤亡 -->
    <template v-if="URL.casualtiesDE == props.url">
      <el-table-column prop="casualties" align="center" min-width="125px">
        <template #header>
          <div>人员伤亡</div>
        </template>
        <template #default="{ row }">
          <DictTag :code="CODE.rysw" :value="row.casualties"></DictTag>
        </template>
      </el-table-column>
      <el-table-column label="时间段" prop="time" align="center" min-width="125px">
        <template #header>
          <div>时间段</div>
        </template>
        <template #default="{ row }">
          <DictTag :code="CODE.sjd" :value="row.time"></DictTag>
        </template>
      </el-table-column>
    </template>
    <!-- 确定评估-结构破坏 -->
    <template v-if="URL.resistEarthquakesDE == props.url">
      <el-table-column label="破坏程度" prop="" align="center">
        <template #default="{ row }">
          <DictTag :code="CODE.phcd" :value="row.damageDegree"></DictTag>
        </template>
      </el-table-column>
    </template>
    <el-table-column prop="value" align="center" min-width="100px">
      <template #header>
        <div>统计值</div>
        <span v-if="URL.casualtiesDE == props.url">（人）</span>
        <span v-if="URL.EconomicLossED == props.url">（万元）</span>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import { URL, CODE } from '@/views/building/index'
import { updateCorrectionValue } from '@/api/building/index'
import { dataMethod } from '@/utils/spanTable.js'
import { areaName } from '@/views/building/index'

const props = defineProps({
  dataList: Array,
  url: String,
  form: Object,
  loading: Boolean,
  isShow:Boolean
})
const emits = defineEmits(['viewTable'])
const { proxy } = getCurrentInstance()

// 合并列
const spanObj = ref()
function objectSpanMethod({ column, rowIndex, columnIndex }) {
  const _row = spanObj.value[column.property] ? spanObj.value[column.property][rowIndex] : 1
  let _col = _row > 0 ? 1 : 0
  if (columnIndex == 0) {
    _col = 3
  }
  if (columnIndex == 1 || columnIndex == 2) {
    _col = 0
  }
  return {
    rowspan: _row,
    colspan: _col
  }
}
// 合并表头
const handerMethod = ({ row, column, rowIndex, columnIndex }) => {
  if (rowIndex == 1) {
    return { display: 'none' }
  }
}

// 修改
const updateRow = row => {
  const { id, correctionValue, casualties, time } = row
  updateCorrectionValue(props.url, { id, correctionValue, casualties, time }).then(res => {
    proxy.$modal.msgSuccess('修改成功！')
    emits('viewTable')
  })
}

watch(() => props.dataList, () => {
  spanObj.value = dataMethod(props.dataList, ['provinceName', 'cityName', 'countyName'])
}, { deep: true })
</script>
<style scoped></style>